from etgui import *
from PageLayout import *

def MakeView():

	oneof=PotGuiOneOf("OneOfInt")
	# Item1 is the label, 1 is the value set in the model
	oneof.AddItem("Item1",1)
	oneof.AddItem("Item2",2)
	popup=PotGuiPopupButton("OneOfPopup")
	popup.AddItem("Do This","this")
	popup.AddItem("Do That","that")

	fun_oneof=PotGuiOneOf("Fun",cr=(0,1))
	fun_oneof.AddItem("This","this")
	fun_oneof.AddItem("is","is")
	fun_oneof.AddItem("Fun","fun")
	fun_popup=PotGuiPopupButton("Fun")
	fun_popup.AddItem("This","this")
	fun_popup.AddItem("is","is")
	fun_popup.AddItem("Fun","fun")
	view=MakeTabSheetLayout(
		TabPage(
			"Fields",
			MakePageLayout(eVObjHExpand|eVObjVCenter,
				Form(
					items=[
						"Martin", PotTextField("Text1"),
						"Robert", PotTextField("Text2",width=10),
						"Int Field", PotGuiIntField("IntValue1",
							IntField(-1,2,0,99) # value is >=0 and <=99
						),
						"Popup",popup,
					]
				)
			)
		),
		TabPage(
			"Text",
			VBox(
				align=eVObjHExpand|eVObjVExpand,
				items=[
					"Enter some text:",
					PotGuiTextView("MultiLineText",TextView(),Point(200))
				]
			)
		),
		TabPage(
			"OneOf",
			MakePageLayout(eVObjHCenter|eVObjVCenter,
				BorderItem("One of",oneof),
				BorderItem("Many of",
					ManyOfCluster(
						PotGuiToggleButton("Toggle1", "Toggle 1"),
						PotGuiToggleButton("Toggle2", "Toggle 2"),
					)
				),
			)
		),
		TabPage(
			"Fun",
			MakePageLayout(eVObjHCenter|eVObjVCenter,
				"Change one and the other observes the model",
				BorderItem("One of",fun_oneof),
				fun_popup,
				PotTextField("Fun"),
			)
		),
	)
	return view

def p(model,slot):
	print `slot`,"=",`model.GetValue(slot)`
# important: keep one copy of the dialog
gDialog=None
def Show():
	global gDialog
	if not gDialog:
		gDialog=MakeOkCancelDialog("My Dialog",PotGuiModel(),MakeView())
	model=gDialog.GetModel()
	model.SetValue("Text1","test1")
	model.SetValue("Text2","test1")
	model.SetValue("IntValue1",42)
	if gDialog.ShowUnderMouse()==CmdNo.cIdOk:
		# now you have access to the fields in the model!
		p(model,"Text1")
		p(model,"Text2")
		p(model,"IntValue1")
		p(model,"MultiLineText")
		p(model,"Toggle1")
		p(model,"Toggle1")
	else:
		print "Cancel"

